import fs from 'fs'
import path from 'path'

export const registeredRouter = function (router) {
  const filePath = fs.readdirSync('./controller').filter(item => item.endsWith('Controller.js')).map(item => `file:///${path.resolve()}/controller/${item}`)
  filePath.forEach(async item => {
    const arr = await import(item)
    arr.default.forEach(obj => {
      if (obj.mathod === 'get') {
        router.get(obj.url, obj.fn)
      }
      if (obj.mathod === 'post') {
        router.post(obj.url, obj.fn)
      }
      if (obj.mathod === 'put') {
        router.put(obj.url, obj.fn)
      }
      if (obj.mathod === 'delete') {
        router.delete(obj.url, obj.fn)
      }
    })
  })
}